unit uListagemPadrao;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, ComCtrls, ExtCtrls, Grids, DBGrids, Buttons, StdCtrls, RXDBCtrl;

type
  TfListagemPadrao = class(TForm)
    Panel1: TPanel;
    SpeedButton1: TSpeedButton;
    SpeedButton2: TSpeedButton;
    SpeedButton3: TSpeedButton;
    SpeedButton4: TSpeedButton;
    Panel2: TPanel;
    edtLocalizar: TEdit;
    Label1: TLabel;
    DBGrid1: TRxDBGrid;
    procedure FormKeyPress(Sender: TObject; var Key: Char);
    procedure SpeedButton4Click(Sender: TObject);
    procedure DBGrid1DblClick(Sender: TObject);
    procedure DBGrid1KeyDown(Sender: TObject; var Key: Word;
      Shift: TShiftState);
    procedure DBGrid1KeyPress(Sender: TObject; var Key: Char);
    procedure FormShow(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  fListagemPadrao: TfListagemPadrao;

implementation

uses uDm;

{$R *.dfm}

procedure TfListagemPadrao.FormKeyPress(Sender: TObject; var Key: Char);
begin

  if key = #27 then
    close;
end;

procedure TfListagemPadrao.SpeedButton4Click(Sender: TObject);
begin
  close;
end;

procedure TfListagemPadrao.DBGrid1DblClick(Sender: TObject);
begin
  if SpeedButton2.Enabled = true then
    SpeedButton2.Click;
end;

procedure TfListagemPadrao.DBGrid1KeyDown(Sender: TObject; var Key: Word;
  Shift: TShiftState);
begin
  if (Key = VK_DELETE) and (SpeedButton3.Enabled = true) then
    SpeedButton3.Click;
end;

procedure TfListagemPadrao.DBGrid1KeyPress(Sender: TObject; var Key: Char);
begin
  if key = #13 then
  begin
    key := #0;
    DBGrid1DblClick(sender);
  end;
end;

procedure TfListagemPadrao.FormShow(Sender: TObject);
begin
  dm.qryPermissoes.Close;
  dm.qryPermissoes.SQLWhere.Clear;
  dm.qryPermissoes.SQLWhere.Add('where permissao.usuario = '+dm.qryUsuarioLogadoCOD_USUARIO.AsString);
  dm.qryPermissoes.SQLWhere.Add('and permissao.tela = '+IntToStr(Tag));
  dm.qryPermissoes.SQLWhere.Add('and permissao.operacao = 1');
  dm.qryPermissoes.Open;
  if dm.qryPermissoes.IsEmpty then
    SpeedButton1.Enabled := false;

  dm.qryPermissoes.Close;
  dm.qryPermissoes.SQLWhere.Clear;
  dm.qryPermissoes.SQLWhere.Add('where permissao.usuario = '+dm.qryUsuarioLogadoCOD_USUARIO.AsString);
  dm.qryPermissoes.SQLWhere.Add('and permissao.tela = '+IntToStr(Tag));
  dm.qryPermissoes.SQLWhere.Add('and permissao.operacao = 2');
  dm.qryPermissoes.Open;
  if dm.qryPermissoes.IsEmpty then
    SpeedButton2.Enabled := false;

  dm.qryPermissoes.Close;
  dm.qryPermissoes.SQLWhere.Clear;
  dm.qryPermissoes.SQLWhere.Add('where permissao.usuario = '+dm.qryUsuarioLogadoCOD_USUARIO.AsString);
  dm.qryPermissoes.SQLWhere.Add('and permissao.tela = '+IntToStr(Tag));
  dm.qryPermissoes.SQLWhere.Add('and permissao.operacao = 3');
  dm.qryPermissoes.Open;
  if dm.qryPermissoes.IsEmpty then
    SpeedButton3.Enabled := false;

  dm.qryPermissoes.Close;
  dm.qryPermissoes.SQLWhere.Clear;
  dm.qryPermissoes.SQLWhere.Add('where permissao.usuario = '+dm.qryUsuarioLogadoCOD_USUARIO.AsString);
  dm.qryPermissoes.SQLWhere.Add('and permissao.tela = '+IntToStr(Tag));
  dm.qryPermissoes.SQLWhere.Add('and permissao.operacao = 4');
  dm.qryPermissoes.Open;
  if not dm.qryPermissoes.IsEmpty then
    SpeedButton1.Enabled := true;

end;

end.
